/**
 * Created by chengming on 18/5/27.
 * version 1.0
 */
const JsonAdapter = require('../JsonAdapter');
const iconv = require("iconv-lite");
const vm = require('vm');
const request = require('request-promise');
const logger = require('../../conf/logger');
const querystring = require("querystring")
const urlencode = require("urlencode")
const cheerio = require('cheerio');

/**
 * cctv app
 * @type {module.Bjp2p}
 */
module.exports = class Infocastfn extends JsonAdapter{

    async reqJson(){
        const body = await this.doRequest();
        let decodeBody = iconv.decode(body, this.encoding).toString();
        let $ = cheerio.load(decodeBody);
        let jsonStr = $('#_infocastNews_WAR_fn_news_infocastNews_dataTableData').text();

        let json = JSON.parse(jsonStr);

        let data = [];
        for(let [x, y, z] of json.aaData){
            data.push({
                title:y,
                href:'http://screen.jin10.com/getContentByInfocastfn?url=' + encodeURIComponent(`http://www.infocastfn.com/fn/ajax/news/newsDetail?newsId=${z}&locale=zh_CN`)
            })
        }

        return {
            data: data
        };
    }

}
